//引入路由
import VueRouter from "vue-router";
// import Message from "element-ui/packages/message/src/main";

// 声明一个路由实例，赋值给router
let router = new VueRouter({
    // 路由列表，写路由的详细规则
    routes: [
        // redirect 重定向
        {path: '/', redirect: '/homePage'},

        // {path: '/message', component: () => import('@/page/message')},
        {
            path: '/index',
            component: () => import('@/page/index'),
            children: [
                {path: '/homePage', component: () => import('@/page/homePage')},
                {path: '/churchyardPage', component: () => import('@/page/churchyardPage')},
                {path: '/overseasPage', component: () => import('@/page/overseasPage')},
                {path: '/MainUser', component: () => import('@/page/MainUser')},
                {path: '/multiPage', component: () => import('@/page/multiPage')},
                {path: '/shopPage', component: () => import('@/page/shopPage')},
                {path: '/addOrder', component: () => import('@/page/addOrder')},
                {path: '/login', component: () => import('@/page/login')},
                {path: '/register', component: () => import('@/page/register')},
                {path: '/commodityPage', component: () => import('@/page/commodityPage')},
            ]
        },
    //    后台
        {path: '/admin', component: () => import('@/pageAdmin/admin')},
        {path: '/adminHome',
            component: () => import('@/pageAdmin/adminHome'),
            children: [
                {path: '/adminLine', component: () => import('@/pageAdmin/adminLine')},
                {path: '/adminGroupbuy', component: () => import('@/pageAdmin/adminGroupbuy')},
                {path: '/adminLinetype', component: () => import('@/pageAdmin/adminLinetype')},
                {path: '/adminPutLine', component: () => import('@/pageAdmin/adminPutLine')},
                {path: '/adminPutBuy', component: () => import('@/pageAdmin/adminPutBuy')},
                {path: '/adminOrder', component: () => import('@/pageAdmin/adminOrder')},
            ]
        },
    ],
    // 设置mode为history，可以去掉路径上的/#/号
    mode: 'history'
})

// // 不需要登录的路径【白名单】
// let notNeedLogin = ['/login', '/register', '/user/create'];
//
// // 每次路由跳转之前执行
// router.beforeEach(((to, from, next) => {
//     // 如果to.path（要访问的路径），不在白名单里
//     if (notNeedLogin.indexOf(to.path) === -1) {
//         // 判断TOKEN是否为空
//         if (localStorage.getItem('TOKEN') == null) {
//             Message.warning('请先登录！');
//             // 拦截并跳转到指定页面
//             next('/login');
//         }
//     }
//     // 放行
//     next();
// }))

// 把router导出供其他模块使用
export default router